<?php
session_start();
error_reporting(0);
if($_SESSION['username']!="")
{
?>
<!DOCTYPE html>
<html lang="en">
  <head>
     <? include "./include/head.php"; ?>
	  <? include "./include/js.php"; ?>
  </head>
  <body>
  <? include "./include/body.php"; ?>
<?php
 include "./config/connection.php";
 include "./config/function_thumb.php";
 
 $id_buktipengiriman = $_POST['id_buktipengiriman'];
 $id_pemesanan = $_POST['id_pemesanan'];
 $lokasi_file = $_FILES['foto']['tmp_name'];
 $nama_file   = $_FILES['foto']['name'];

  if(empty($id_buktipengiriman) || empty($id_pemesanan))
 {
	header ("location:transfer_add.php?page=input&input=invalid");
 }
 else{	
	if(empty($nama_file)){
		$exec="UPDATE bukti_pengiriman SET id_pemesanan='$id_pemesanan' WHERE id_buktipengiriman='$id_buktipengiriman'";
	}
	else{
		$hasil=mysql_query("SELECT foto FROM bukti_pengiriman WHERE id_buktipengiriman='$id_buktipengiriman'");
		if(mysql_num_rows($hasil)>0) $data=mysql_fetch_array($hasil);
		if(file_exists('foto/foto_pengiriman/$data[foto]')) unlink('foto/foto_pengiriman/$data[foto]');		
		if(file_exists('foto/foto_pengiriman/kecil_$data[foto]')) unlink('foto/foto_pengiriman/kecil_$data[foto]');	
		
		$exec="UPDATE bukti_pengiriman SET id_pemesanan='$id_pemesanan',foto='$nama_file' WHERE id_buktipengiriman='$id_buktipengiriman'";
		UploadPengiriman($nama_file);
	}
	
	$sukses_update = mysql_query($exec);
	if($sukses_update){
		
		echo"<script>alert('Data Berhasil Diubah ')</script>";
		echo"<script>history.go(-2);</script>";
	}
	else{
		header ("location:transfer_edit.php?input=invalid");
	} 
 }
 ?>
 <? include "./include/menubawah.php"; ?>
    <?php
    ?>
  </body>
</html>
<?php
    }
else {
    include 'warning.php';
}
?>